const app = getApp()
Page({
  data: {
    currentTab: 0, //预定的位置
    datalist: [],
    loadingHidden: true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.showToast({
      title: '加载中..',
      icon: 'loading',
      //duration: 1500
    });
    this.listdata()
  },
  /**
 * 生命周期函数--监听页面显示
 */
  onShow: function () {
    wx.showToast({
      title: '加载中..',
      icon: 'loading',
      //duration: 1500
    });
    this.listdata()
  },
  aa:function(a){
      console.log(a)
      return '6666'
  },
  //查询数据 
  listdata: function() {
    var that=this;
    wx.request({
      url: app.globalData.the_host + `/product/recommended?count=100&tenant=t1`,
      data: {},
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
       
        that.saixuan(res.data)
        that.setData({
          datalist:res.data,
        });
        wx.hideToast();//隐藏提示框
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  //跳转
  bindtapitem:function(e){
    let code = JSON.stringify(e.currentTarget.dataset.code)
    wx.navigateTo({
      url: '../details/index?code=' + code
    })
  },
  //筛选
  saixuan:function(list){
    var arr=[]
    for (let i = 0; i < list.length; i++) {
      for (let a = 0; a < list[i].resources.length; a++) {
        if (list[i].resources[a].type == 0) {
          arr.push(list[i].resources[a].url);
          break;
        }
      }
    }
    this.setData({
      imglist: arr,
    });
    console.log(arr)
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // 显示顶部刷新图标
    wx.showNavigationBarLoading();
    console.log('下啦')
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('上啦')
  },
})